#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include "myBsp.h"	//add



static uint8_t uc_LedDebugEnable = 1;




/// 数据结构实体---按键
//BSP_KEY_T_INTERFACE Bsp_t_Key1 = {0};
//BSP_KEY_T_INTERFACE Bsp_t_Key2 = {0};

/// 数据结构实体---LED
BSP_LED_T_INTERFACE Bsp_t_LedY = {0};
BSP_LED_T_INTERFACE Bsp_t_LedG = {0};
BSP_LED_T_INTERFACE Bsp_t_LedR = {0};



//static void Bsp_OsDelay_ms(uint16_t _us_time_ms)
//{
//    MODULE_OS_DELAY_MS(_us_time_ms);
//}


static void Bsp_LedY_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LEDY_PORT, BSP_LED_LEDY_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LEDY_PORT, BSP_LED_LEDY_PIN, GPIO_PIN_RESET);
    }
}
static void Bsp_LedG_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LEDG_PORT, BSP_LED_LEDG_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LEDG_PORT, BSP_LED_LEDG_PIN, GPIO_PIN_RESET);
    }
}

static void Bsp_LedR_OnOff(uint8_t _trueOrFalse)
{
    if (_trueOrFalse == true)
    {
        HAL_GPIO_WritePin(BSP_LED_LEDR_PORT, BSP_LED_LEDR_PIN, GPIO_PIN_SET);
    }
    else
    {
        HAL_GPIO_WritePin(BSP_LED_LEDR_PORT, BSP_LED_LEDR_PIN, GPIO_PIN_RESET);
    }
}










void Bsp_Init(void)
{

    // LED
    memset((char *)&Bsp_t_LedY, 0, sizeof(Bsp_t_LedY));
    Bsp_t_LedY.t_Input.fnp_LedOnOff = Bsp_LedY_OnOff;
    //Bsp_t_LedY.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_LedY);
	
    memset((char *)&Bsp_t_LedG, 0, sizeof(Bsp_t_LedG));
    Bsp_t_LedG.t_Input.fnp_LedOnOff = Bsp_LedG_OnOff;
    //Bsp_t_LedG.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_LedG);
	
    memset((char *)&Bsp_t_LedR, 0, sizeof(Bsp_t_LedR));
    Bsp_t_LedR.t_Input.fnp_LedOnOff = Bsp_LedR_OnOff;
    //Bsp_t_LedR.t_Input.fnp_DebugOutStr = Bsp_DebugOutStr;
    BspLed_Init(&Bsp_t_LedR);
		
}



void Bsp_Cycle_1ms(void)
{

    Bsp_t_LedY.t_Transplant.fnp_Cycle_1ms(&Bsp_t_LedY);
    Bsp_t_LedG.t_Transplant.fnp_Cycle_1ms(&Bsp_t_LedG);
    Bsp_t_LedR.t_Transplant.fnp_Cycle_1ms(&Bsp_t_LedR);

}
/**
 * @brief
 */
void Bsp_Cycle_10ms(void)
{
//    Bsp_t_Key1.t_Transplant.fnp_Cycle_10ms(&Bsp_t_Key1);
//    Bsp_t_Key2.t_Transplant.fnp_Cycle_10ms(&Bsp_t_Key2);
}
/**
 * @brief
 */
void Bsp_Cycle_100ms(void)
{
    //Bsp_Adc_Cycle_100ms();
    //Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_TOGGLE, BSP_LED_E_PRIORITY_LOW);//????
    /*BspUsbHostUDisk_Cycle_100ms();*/
    Bsp_t_LedY.t_Transplant.fnp_Cycle_100ms(&Bsp_t_LedY);
    Bsp_t_LedG.t_Transplant.fnp_Cycle_100ms(&Bsp_t_LedG);
    Bsp_t_LedR.t_Transplant.fnp_Cycle_100ms(&Bsp_t_LedR);

	
}
/**
 * @brief
 */
void Bsp_Cycle_1000ms(void)
{
//    Bsp_t_Key1.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Key1);
//    Bsp_t_Key2.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Key2);
//    Bsp_t_Nebulizer.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Nebulizer);
//    Bsp_t_Bq4050.t_Transplant.fnp_Cycle_1000ms(&Bsp_t_Bq4050);
//    Bsp_LedDebugCycle_1000ms();
}

//void Bsp_LedDebugCycle_1000ms(void)//this function not work!!!!!?????在哪赋值？？？？或调用？？
static void Bsp_LedDebugCycle_1000ms(void)
{
    static uint8_t uc_cmt = 0;
    if (uc_LedDebugEnable == 1)
    {
				printf("in enable\r\n");
        uc_cmt++;
        switch (uc_cmt)
        {
        case 1:
					printf("case1\r\n");
            Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 2:
					printf("case2\r\n");
            Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        case 3:
					printf("case3\r\n");
            Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_ON, BSP_LED_E_PRIORITY_HIGH);
            break;

        default:
					printf("case default\r\n");
            uc_cmt = 0;
            Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
            break;
        }
    }
    else
    {
        uc_cmt = 0;
    }
}
/**
 * @brief   Debug接口函数
 * @note    开启Debug相关指令后会循环点亮，关闭Debug后所有LED全部关闭
 * @param   _uc_trueOrFalse-判断指令进入与退出
 * @return  None
 */
void Bsp_LedDebugTestOnOff(uint8_t _uc_trueOrFalse, void *_vp_context)
{
    if (_uc_trueOrFalse == true)
    {
        uc_LedDebugEnable = 1;
        Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_OFF, BSP_LED_E_PRIORITY_HIGH);

    }
    else
    {
        uc_LedDebugEnable = 0;
        Bsp_t_LedY.t_Output.fnp_SetMode(&Bsp_t_LedY, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_LedG.t_Output.fnp_SetMode(&Bsp_t_LedG, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);
        Bsp_t_LedR.t_Output.fnp_SetMode(&Bsp_t_LedR, BSP_LED_E_MODE_NULL, BSP_LED_E_PRIORITY_HIGH);

    }
}





